<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ include file="/jsp/common/common.jsp"%>  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title></title>
		<meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">
		<link rel="stylesheet" type="text/css" href="<c:url value="/static/jquery-easyui/themes/default/easyui.css"/>">
		<link rel="stylesheet" type="text/css"
			href="<c:url value="/static/jquery-easyui/themes/icon.css"/>">
		<script type="text/javascript"
			src="<c:url value="/static/jquery-easyui/jquery-1.6.min.js"/>"></script>
		<script type="text/javascript"
			src="<c:url value="/static/jquery-easyui/jquery.easyui.min.js"/>"></script>
		<script type="text/javascript"
			src="<c:url value="/static/jquery-easyui/plugins/jquery.panel.js"/>"></script>
		<script type="text/javascript"
			src="<c:url value="/static/jquery-easyui/plugins/jquery.datagrid.js"/>"></script>
		<script type="text/javascript"
			src="<c:url value="/static/jquery-easyui/plugins/jquery.messager.js"/>"></script>
		<script type="text/javascript"
			src="<c:url value="/static/jquery-easyui/ext-for-framework.js.jsp"/>"></script>
		<script type="text/javascript" src="<c:url value="/static/jquery-easyui/locale/easyui-lang-zh_CN.js"/>"></script>	
		<script type="text/javascript"
			src="<c:url value="/static/js/common.js"/>"></script>		
		<script>
		
			function initList(listDisplayEId) {
				$('#' + listDisplayEId).datagrid(
						{
							nowrap : false,
							striped : true,
							collapsible : true,
							remoteSort : true,
							notSelectByRow : false,
							/* frozenColumns : [ [ {
								field : 'ids',
								checkbox : true
							} ] ], */
							toolbar : [
									{
										id : listDisplayEId + '_btn_add',
										text : '新增',
										iconCls : 'icon-add',
										handler : function() {
											 var new_win = window.open("<c:url value='/jsp/openIndexSun.jsp?url=/food/preSaveFood.do'/>","sun","width=1200px,height=600px,status=no,scrollbars=yes");
										     new_win.focus();
											 $('#'+listDisplayEId).datagrid('reload');
										}
									},'-',
									{
										id : listDisplayEId + '_btn_edit',
										text : '修改',
										iconCls : 'icon-edit',
										handler : function() {
										
											var row = $('#'+listDisplayEId).datagrid('getSelections');
 											if(row.length == 0){
												$.messager.alert('提示','请选择一条记录操作！','info');
												return;
											}else{
												//window.showModalDialog("<c:url value='/food/preUpdateFood.do'/>"+"?foodId="+row[0]['foodId'],"","dialogWidth=800px;dialogHeight=500px,status=no");
												window.open("<c:url value='/jsp/openIndexSun.jsp?url=/food/preUpdateFood.do'/>"+"?foodId="+row[0]['foodId'],"sun","width=1200px,height=600px,status=no,scrollbars=yes");

												$('#'+listDisplayEId).datagrid('reload');
											}
											$('#'+listDisplayEId).datagrid('clearSelections');
										}
									},
									{
										id : listDisplayEId + '_btn_del',
										text : '删除',
										iconCls : 'icon-cancel',
										handler : function() {
											
					var row = $('#'+listDisplayEId).datagrid('getSelections');		
					if(row.length == 0){
						$.messager.alert('提示','请选择一条记录操作！','info');
						return;
					}else{
						var str = "foodId="+row[0]['foodId'];	
  						$.messager.confirm('提示', '是否删除该条记录？', function(r){
							if (r){			
								$.ajax({type:'post',url:"<c:url value='/food/deleteFood.do'/>",data:str,dataType:"json",//设置查询参数及提交路径
							 		success:function(data){
										if(data.success){
											$.messager.alert("提示", "删除成功！", 'info');
											$('#'+listDisplayEId).datagrid('reload');
										}else{
											$.messager.alert("提示", data.msg, 'warning');
										}
									},
									error:function(){
										$.messager.alert("错误", "系统错误，请联系管理员！", 'error');
									}
								});
							}
							$('#'+listDisplayEId).datagrid('reload');
							$('#'+listDisplayEId).datagrid('clearSelections');
						});
					}
				
										}
									}],
							onLoadError:function(){
								$.messager.alert('错误','获取数据失败，请与管理员联系！','error');
							}
						 ,onClickRow:function(rowIndex){
								$(".myrad").prop("checked",false);
								$(".myrad").eq(rowIndex).prop("checked",true);
							} 
						});
			};
			$(document).ready(function() {
				initList('listDisplay');
			});
			 
			function formatRadio(value,rowData,rowIndex){
				return value="<input type='radio' class='myrad'  name='radioFood' />";
			}
			 
			//下拉框
			$(function() {        
		        // 下拉框选择控件，下拉框的内容是动态查询数据库信息  
		        $('#foodType1').combobox({   
		            data:[{"foodType1":"0","ordStateName":"全部"},{"foodType1":"1","ordStateName":"牛肉类"},{"foodType1":"2","ordStateName":"海鲜类 "},{"foodType1":"3","ordStateName":"水发类"},{"foodType1":"4","ordStateName":"猪肉类"},{"foodType1":"5","ordStateName":"浇头"},{"foodType1":"6","ordStateName":"鸭肉类"},{"foodType1":"7","ordStateName":"鸡肉类"},{"foodType1":"8","ordStateName":"鸡蛋类"},{"foodType1":"9","ordStateName":"鹌鹑类"},{"foodType1":"10","ordStateName":"河鲜类"},{"foodType1":"11","ordStateName":"豆制品类"},{"foodType1":"12","ordStateName":"根茎类"},{"foodType1":"13","ordStateName":"鸭蛋类"},{"foodType1":"14","ordStateName":"干货类"},{"foodType1":"15","ordStateName":"绿叶菜"},{"foodType1":"16","ordStateName":"瓜果类"},{"foodType1":"17","ordStateName":"叶菜"},{"foodType1":"18","ordStateName":"其他类"},{"foodType1":"19","ordStateName":"猪骨类"},{"foodType1":"20","ordStateName":"蛋类"},{"foodType1":"21","ordStateName":"酸辣"},{"foodType1":"22","ordStateName":"咸菜类"},{"foodType1":"23","ordStateName":"鱼头类"},{"foodType1":"24","ordStateName":"猪血"}],   
		            editable:false, //不可编辑状态  
		            cache: false,  
		            valueField:'foodType1',     
		            textField:'ordStateName',  
		        });      
		    });
			
			function searchInfo(){
				if($('#foodType1').combobox('getValue') ==''){
					$('#listDisplay').datagrid('load', {
						foodType1 : 0,
						foodName : $('#foodName').val(),
						foodMtype : $('#foodMtype').val(),
						foodMname : $('#foodMname').val()
					}); 
				}else{
					$('#listDisplay').datagrid('load', {
						foodType1 : $('#foodType1').combobox('getValue'),
						foodName : $('#foodName').val(),
						foodMtype : $('#foodMtype').val(),
						foodMname : $('#foodMname').val()
					});  
				}
			}
			function  goDetailedContent(val,rowData,rowIndex){
				return '<a href="#" onclick="constructionManager(\'' + rowData.foodId+ '\')">'+val+'</a>  '
			}
			
			function constructionManager(foodId) {
				//window.showModalDialog("<c:url value='/order/goSelectCustomDetailed.do'/>"+"?id="+id, "","dialogWidth=1200px;dialogHeight=500px,status=no");
				var new_win = window.open("<c:url value='/jsp/openIndexSun.jsp?url=/food/goFoodMaterDetailed.do'/>"+"?foodId="+foodId,"sun","width=1200px,height=600px,status=no,scrollbars=yes");
				new_win.focus();
			}
		</script>
			</head>
			<body>
			<table width="98%">
			<tr><td>
			<div style="height: auto; width:1180px;background: #fafafa; padding: 5px;" class="easyui-panel" title="查询" iconCls="icon-search" collapsible="true" minimizable="false" maximizable="false" closable="false">
					<form id="searchForm" name="searchForm" method="post"
						action="userlist.txt"
						onsubmit="return searchDGData(this.id,'listDisplay');">
						<div>
		            	<table cellpadding="5">
								<tr>
									<td>菜名：</td>
									<td><input class="easyui-validatebox" id="foodName" editable="true" name="foodName"></input></td>
									<td>类别：</td>
									<td><input class="easyui-combobox" id="foodType1" editable="false" name="foodType1"></input></td>
									<td>主料大全：</td>
									<td><input class="easyui-validatebox" id="foodMtype" editable="true" name="foodMtype"></input></td>
									<td>主料半成品名称：</td>
									<td><input class="easyui-validatebox" id="foodMname" editable="true" name="foodMname"></input></td>
									
									
		                    		<td><input type="button" onclick="searchInfo()" value="查询"></td>
		                    	</tr>
		                </table>					 
						</div>
					</form>
				</div>
			</td></tr>
		<tr>
		<td>
			<table id="listDisplay" title="菜品列表" 
			iconCls="icon-list" singleSelect="true" idField="foodId"
			url="<c:url value="/food/findFoodIndex.do"/>" loadMsg="请稍候......"
			pagination="true" pageSize="20"
			pageList="[10,20,30,40,50,100]" sortName="foodId"
			rownumbers="true" sortOrder="asc">
			<thead>
				<tr>
				    <th field="foodRole" width="25" formatter="formatRadio"  >
					</th> 
				    <th field="foodId" width="80"  sortable="true" >
						菜品ID
					</th>	
 					<th field="foodName" width="80"  sortable="true" >
						菜名
					</th>		
					<th field="foodType" width="60"  formatter="formatFoodType" sortable="true" >
						品别
					</th>	
					<th field="foodType1" width="60" formatter="formatFoodType1" sortable="true"  >
						类别
					</th>	
					<th field="foodMtype" width="60"  sortable="true" >
						主料大全
					</th>	
					<th field="foodMname" width="100" sortable="true" >
						主料半成品名称
					</th>	
					<th field="foodMater" width="260" formatter="goDetailedContent" sortable="true" >
						所需材料(净料重量)
					</th>	
 				</tr>
			</thead>
			</table>
			</td>
			</tr>
		</table>
	</body>
</html>